﻿<template>
    <div></div>
</template>
<script>
export default {
    name: 'qrcode_index',
    data() {
        return {
            isLoading: true,
            code: this.$route.params.code,
            queryParams: {} // 目标路由参数，用于获取微信授权后的重定向回来的路由参数
        };
    },
    methods: {
        /**
         * 初始化
         */
        init() {
            // 获取code
            this.code = this.code || this.$route.query.code;
            if (!this.code) {
                this.getQueryParams();
            }
            // 标记首次进入
            window.sessionStorage.setItem('qrcode_mark', 'true');
            this.$router.push({ path: '/qrcode/event-handling', query: {code: this.code} });
        },
        /**
         * 获取浏览器地址栏参数
         */
        getQueryParams() {
            let url = location.search;
            if (!url) {
                url = location.hash.replace('#', '');
            }
            if (url.indexOf('?') !== -1) {
                let str = url.split('?')[1];
                let urlParams = {};
                const params = str.split('&');
                for (let item of params) {
                    urlParams[item.split('=')[0]] = item.split('=')[1];
                }
                if (urlParams.state) {
                    const states = decodeURIComponent(urlParams.state).split('?');
                    if (states[1]) {
                        const params = states[1].split('&');
                        for (let param of params) {
                            this.queryParams[param.split('=')[0]] = param.split('=')[1];
                        }
                    }
                    if (this.queryParams.code) {
                        this.code = this.queryParams.code;
                    }
                }
            }
        }
    },
    mounted() {
        this.init();
    }
};
</script>
